cap program drop labelingvars
program define labelingvars

    local input_string = "`1'"
    
    *labelling
	*drop all labels
	* List all variables
	qui ds *`input_string'*
	* Store the list in a local macro
	local vars `r(varlist)'

	* Loop through each variable and clear its label
	foreach var of local vars {
		label variable `var' ""
	}

	* List all variables
	qui ds
	* Store the list in a local macro
	local vars `r(varlist)'
	* Loop through each variable
	foreach var of local vars {
		if strpos("`var'", "`input_string'") {
			label variable `var' "`input_string'"
            if strpos("`var'", "Ps") {
                local current_label : variable label `var'
                label variable `var' "predicted `current_label'"
            }
            if strpos("`var'", "ln") {
                local current_label : variable label `var'
                label variable `var' "ln`current_label'"
            }
            if strpos("`var'", "DP") {
                local current_label : variable label `var'
                label variable `var' "`current_label' PPIupd"
            }
            if strpos("`var'", "LP") {
                local current_label : variable label `var'
                label variable `var' "`current_label' PPI05$"
            }
            if strpos("`var'", "MP") {
                local current_label : variable label `var'
                label variable `var' "`current_label' PPI95$"
            }
            if strpos("`var'", "LG") {
                local current_label : variable label `var'
                label variable `var' "`current_label' GDP05$"
            }
            if strpos("`var'", "MG") {
                local current_label : variable label `var'
                label variable `var' "`current_label' GDP95$"
            }
            if strpos("`var'", "t_") {
                local current_label : variable label `var'
                label variable `var' "`current_label' total"
            }
            if strpos("`var'", "m_") {
                local current_label : variable label `var'
                label variable `var' "`current_label' manuf"
            }
            if strpos("`var'", "ALL") {
                local current_label : variable label `var'
                label variable `var' "`current_label' across all countries"
            }
            if strpos("`var'", "shr") {
                local current_label : variable label `var'
                label variable `var' "`current_label' shr"
            }
            if strpos("`var'", "hq") {
                local current_label : variable label `var'
                label variable `var' "`current_label' HQ"
            }
            if strpos("`var'", "home") {
                local current_label : variable label `var'
                label variable `var' "`current_label' domestic"
            }
            if strpos("`var'", "foreign") {
                local current_label : variable label `var'
                label variable `var' "`current_label' foreign"
            }
            if strpos("`var'", "shr2") {
                local current_label : variable label `var'
                label variable `var' "`current_label' normalized weights"
            }
            if strpos("`var'", "wtd") {
                local current_label : variable label `var'
                label variable `var' "`current_label' patent weighted"
            }
            if strpos("`var'", "itd") {
                local current_label : variable label `var'
                label variable `var' "`current_label' pat. wgt. lintrate set"
            }
            if strpos("`var'", "mtd") {
                local current_label : variable label `var'
                label variable `var' "`current_label' pat. wgt. minwage set"
            }
        }
	}	
end
